; Constants
multiboot_magic equ 0xe85250d6 ; multiboot2
multiboot_validate_magic equ 0x36d76289 ; for some reason, it's different from the other magic
multiboot_arch equ 0 ; i386 

; Multiboot
section .multiboot 
align 8
multiboot_header:
    dd multiboot_magic 
    dd multiboot_arch
    dd multiboot_header_end - multiboot_header 
    dd -(multiboot_magic + multiboot_arch + multiboot_header_end - multiboot_header)
    
    ; after that come the multiboot tags
    ; multiboot information request 
    dw 1
    dw 0
    dd 16 
    dd 2 ; request boot loader name tag
    dd 8 ; request framebuffer info

    ; multiboot terminator 
    align 8
    dw 0
    dw 0
    dd 8
multiboot_header_end:


; Code
extern kernel_main
extern kernel_error_code

section .text
global _start
_start:
    mov esp, stack_top ; stack setup

    cmp eax, multiboot_validate_magic ; check if multiboot was used
    jne not_multiboot

    push ebx ; pass multiboot structure to the kernel 

    call kernel_main

not_multiboot:
    mov dword [kernel_error_code], 0x1 ; not multiboot
    jmp _loop_of_death

global _loop_of_death
_loop_of_death:
    jmp _loop_of_death

; Stack and stuff
section .bss
align 16 
resb 65536 ; 64 KiB stack should be fine
stack_top:

